package paskal.ui.components;

import java.awt.Color;
import java.awt.Font;
import java.awt.Point;
import java.awt.Rectangle;
import java.util.Map;

import javax.swing.JLabel;

import paskal.ui.Style;

public class Label extends JLabel implements Component {
	private static final long serialVersionUID = 6305711894539272108L;

	public Label() {
	}

	public Label(String text) {
		super(text);
	}

	@Override
	public void stylize(String selector) {
		Style.getInstance().styleThisShit(selector, this);
	}

	@Override
	public void setProperty(String key, Object value) {
		switch (key) {
		case "bounds": {
			setBounds((Rectangle) value);
			break;
		}
		case "color": {
			setForeground(new Color(Integer.parseInt(value.toString()
					.substring(1), 16)));
			break;
		}
		case "background": {
			@SuppressWarnings("unchecked")
			Map<String, Object> background = (Map<String, Object>) value;
			Point p = (Point) background.get("position");
			if (p != null) {
				Rectangle r = new Rectangle(p);
				r.height = getHeight();
				r.width = getWidth();
				setIcon(Style.getInstance().getImageIcon(
						(String) background.get("image"), r));
			} else {
				setIcon(Style.getInstance().getImageIcon(
						(String) background.get("image")));
			}
			break;
		}
		case "font": {
			@SuppressWarnings("unchecked")
			Map<String, Object> font = (Map<String, Object>) value;
			Font f = new Font(font.get("name").toString(),
					(int) font.get("style"), (int) font.get("size"));
			setFont(f);
			break;
		}
		default:
			break;
		}
	}
}
